<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #yanz {
            width: 50px;
            height: 20px;
        }

        #demo {
            width: 50px;
            height: 20px;
            line-height: 20px;
            border: 1px solid gray;
            text-align: center;
            margin-top: 20px;
        }
    </style>
</head>

<body>
    <input type="text" id="yanz">
    <div id="demo"></div>
    <br>
    <button id="btn">确定</button>

    <script>
        var inp = document.getElementById('yanz')
        var pic = document.getElementById('demo')
        var btn = document.getElementById('btn')
        var number = parseInt(Math.random() * (9000) + 1000)
        pic.innerHTML = number
        btn.onclick = function () {
            inp.value == number ? alert("保存成功") : alert("保存失败")
        }
        pic.onclick = function () {
            number = parseInt(Math.random() * (9000) + 1000)
            pic.innerHTML = number
        }
    </script>
</body>

</html>